package com.example.service;

import cn.hutool.core.date.DateUtil;
import com.example.entity.Admin;
import com.example.entity.PetActionLog;
import com.example.mapper.AdminMapper;
import com.example.mapper.PetActionLogMapper;
import com.example.utils.TokenUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author HY
 * @date 2025/2/16
 */
@Service
public class PetActionLogService {
    @Autowired
    private PetActionLogMapper petActionLogMapper;
    @Autowired
    private AdminMapper adminMapper;

    public PageInfo<PetActionLog> selectPage(PetActionLog petActionLog, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<PetActionLog> list = petActionLogMapper.selectAll(petActionLog);
        return PageInfo.of(list);
    }

    public void add(PetActionLog petActionLog) {
        Admin admin = adminMapper.selectById(TokenUtils.getCurrentUser().getId());
        petActionLog.setUserName(admin.getName());
        petActionLogMapper.insert(petActionLog);
    }
}
